package com.alex.web.bean;

/**
 * 通用返回值对象
 */
public class CommonResult {

    public static int CODE_EXCEPTION = -1;
    public static int CODE_SUCCESS = 1;
    public static int CODE_ERROR = 0;

    //默认提示消息
    private static final String MSG_EXCEPTION = "异常";
    private static final String MSG_SUCCESS = "成功";
    private static final String MSG_FAIL = "失败";
    private static final String RESULT_OBJECT = "";

    private int code;
    private String msg;
    private Object resultObject;

    public static void main(String[] args) {
        CommonResult result = CommonResult.successResult();
        System.out.println(result.getResultObject().toString());
    }

    public CommonResult(){

    }

    public CommonResult(int code, Object object){
        this.code = code;
        this.resultObject = object;
    }

    public CommonResult(int code, String msg, Object object){
        this.code = code;
        this.msg = msg;
        this.resultObject = object;
    }

    /**
     * 成功返回，默认提示信息
     *
     * @return Result
     */
    public static CommonResult successResult() {
        CommonResult result = new CommonResult(CODE_SUCCESS, MSG_SUCCESS, RESULT_OBJECT);
        return result;
    }

    /**
     * 成功返回，默认提示信息，返回传入的对象
     *
     * @return Result
     */
    public static CommonResult successResult(Object resultObject) {
        CommonResult result = new CommonResult(CODE_SUCCESS, MSG_SUCCESS, resultObject);
        return result;
    }

    /**
     * 成功返回，返回传入的消息和对象
     *
     * @return Result
     */
    public static CommonResult successResult(String msg, Object resultObject) {
        CommonResult result = new CommonResult(CODE_SUCCESS, msg, resultObject);
        return result;
    }

    /**
     * 成功返回，返回传入的CODE、消息和对象
     *
     * @return Result
     */
    public static CommonResult successResult(int code, String msg, Object resultObject) {
        CommonResult result = new CommonResult(code, msg, resultObject);
        return result;
    }


    /**
     * 失败返回，默认提示信息
     *
     * @return Result
     */
    public static CommonResult failResult() {
        CommonResult result = new CommonResult(CODE_ERROR, MSG_FAIL, RESULT_OBJECT);
        return result;
    }

    /**
     * 失败返回，默认提示信息，返回传入的对象
     *
     * @return Result
     */
    public static CommonResult failResult(Object resultObject) {
        CommonResult result = new CommonResult(CODE_ERROR, MSG_FAIL, resultObject);
        return result;
    }

    /**
     * 失败返回，返回传入的消息和对象
     *
     * @return Result
     */
    public static CommonResult failResult(String msg, Object resultObject) {
        CommonResult result = new CommonResult(CODE_ERROR, msg, resultObject);
        return result;
    }

    /**
     * 失败返回，返回传入的CODE、消息和对象
     *
     * @return Result
     */
    public static CommonResult failResult(int code, String msg, Object resultObject) {
        CommonResult result = new CommonResult(code, msg, resultObject);
        return result;
    }


    /**
     * 异常返回，默认提示信息，返回默认信息
     *
     * @return Result
     */
    public static CommonResult exceptionResult() {
        CommonResult result = new CommonResult(CODE_EXCEPTION, MSG_EXCEPTION, RESULT_OBJECT);
        return result;
    }

    /**
     * 异常返回，默认提示信息，返回传入的对象
     *
     * @return Result
     */
    public static CommonResult exceptionResult(Object resultObject) {
        CommonResult result = new CommonResult(CODE_EXCEPTION, MSG_EXCEPTION, resultObject);
        return result;
    }

    /**
     * 异常返回，返回传入的消息和对象
     *
     * @return Result
     */
    public static CommonResult exceptionResult(String msg, Object resultObject) {
        CommonResult result = new CommonResult(CODE_EXCEPTION, msg, resultObject);
        return result;
    }

    /**
     * 异常返回，返回传入的code、消息和对象
     *
     * @return Result
     */
    public static CommonResult exceptionResult(int code, String msg, Object resultObject) {
        CommonResult result = new CommonResult(code, msg, resultObject);
        return result;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getResultObject() {
        return resultObject;
    }

    public void setResultObject(Object resultObject) {
        this.resultObject = resultObject;
    }
}
